//
//  KAExitReasonCell.swift
//  kano
//
//  Created by Frank on 2025/5/15.
//

import UIKit

class KAExitReasonCell: UITableViewCell {
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    let titleLabel = UILabel()
    let icon = UIImageView()
    let contentBgView = UIView()
    
    var isSelectedCell: Bool = false {
        didSet {
            icon.image = isSelectedCell ? UIImage(named: "checkCircle_sel") : UIImage(named: "checkCircle_unsel")
        }
    }
    
    var tapAction: (() -> Void)?
    
    static func ka_cell(for tableView: UITableView) -> KAExitReasonCell {
        let var_identifityId = NSStringFromClass(self)
        var var_cell = tableView.dequeueReusableCell(withIdentifier: var_identifityId)
        if var_cell == nil {
            var_cell = KAExitReasonCell.init(style: .default, reuseIdentifier: var_identifityId)
        }
        return var_cell as! KAExitReasonCell
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews() {
        backgroundColor = .clear
        contentView.addSubview(contentBgView)
        contentBgView.addSubview(icon)
        contentBgView.addSubview(titleLabel)
        
        contentBgView.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(kscale(36))
            make.right.equalToSuperview().offset(kscale(-30))
        }
                    
        icon.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(kscale(10))
            make.width.height.equalTo(kscale(16))
        }
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(icon)
            make.left.equalTo(icon.snp.right).offset(kscale(10))
            make.right.equalToSuperview().offset(kscale(-10))
        }
        
        titleLabel.numberOfLines = 1
        titleLabel.font = .systemFont(ofSize: kscale(12))
        titleLabel.textColor = UIColor.ka_hexColor(0x999999)
        contentBgView.backgroundColor = UIColor.ka_hexColor(0xF4F6FB)
    }
    
}
